<!--
 * 该组件与同级的warehouseSelect基本相同功能，只是请求是请求的oms仓库信息，
 * 由于oms可以看到“启用库位管理”字段为“关闭”的仓库，所以与wms显示数据略有不同
 -->
<template>
  <el-select v-model="value" filterable placeholder="请选择" @change="changeValue($event)" clearable style="width:100%">
    <el-option
      v-for="item in warehouses"
      :key="item.code"
      :label="item.name"
      :value="item.code"
    />
  </el-select>
</template>
<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      value: '',
      warehouses: [],
      callbackMethod: '',
      warehouseName: '',
      shipmentCode: '',
    }
  },
  created() {
    this.init()
  },
  methods: {
    init(shipmentCode = '', warehouseName = ''){
      this.warehouseName = warehouseName;
      this.shipmentCode = shipmentCode;
      return this.findList();
    },
    findList() {
      return request({
        url: '/wms/warehouseShipment/chooseOmsWarehouseData',
        method: 'get',
        params: { warehouseName: this.warehouseName, shipmentCode: this.shipmentCode }
      }).then(response => {
        this.warehouses = response.data
      })
    },

    changeValue(e) {
      this.$emit("setWarehouseCode", e)
    },

    setSelectValue(shipmentCode, value) {
      this.init(shipmentCode).then(()=>{
        if(value!=''){
          this.warehouses.forEach(i =>{
            if(i.code == value){
              this.value = i.name
            }
            if(i.name == value){
              this.value = value
            }
          })
        }else{
          this.value = value
        }
      })
    },
  }
}
</script>
